#!/usr/bin/env bash


### To set up CGI access, use this script
### We expect all the environment variables like
###    'REDIRECT_URL', 'HTTP_COOKIE', 'REMOTE_ADDR', 'CONTENT_LENGTH' ...
### to be available.

### The file public-directory/.htaccess should contain something like:
#
# <IfModule mod_rewrite.c>
#         RewriteEngine on
#         RewriteBase /public-directory/
# 
#         RewriteRule ^(.*)$       /cgi-bin/python-pages/cgi.sh [L]
# 
# </IfModule>

### Don't forget to set the public-directory variable in config.xml

### Uncomment the next lines to test cgi access
#
# echo Content-Type: text/plain 
# echo  
# echo "CGI should work if you can read this through your browser"
# echo $REDIRECT_URL
# exit 


# Installation directory
case `hostname` in
	'megatux')
		root='/home/jonathan/repositories/python-pages-google-code/python-pages/application'
		;;
	'macbook-jonathan')
		root='/Users/jonathanslenders/Documents/repositories/python-pages/application'
		;;
	'hercules')
		root='/web/jonathan/slenders.be/www/cgi-bin/website2/python-pages/application'

		# Run my own local installation of Python
		export PATH=/web/jonathan/slenders.be/www/cgi-bin/python-2.5.2-local/bin/:$PATH
		;;
	*)
		echo "ERROR: please add your installation directory and host name in the cgi.sh script"
		exit 1
		;;
esac

### Configuration file
export SEAGULL_CONFIG=config.xml

### PYTHONPATH variable
export PYTHONPATH=$PATHONPATH:$root:$root/libs

### Start server
cd $root

./seagull/server.py --cgi



### I noticed that it's not necessary to pass stdin the following way.
### Some servers even result in Internal Server Error after doing this.
### However, this may be useful for debugging.
# ./seagull/server.py --cgi < /dev/stdin

### When the server does not run, you may try
### the next line instead to debug
# ./seagull/server.py --cgi > /tmp/python-pages-output
